package in.iqing.view.activity;

import android.os.Bundle;

import in.iqing.base.BaseActivity;
import in.iqing.control.util.IntentUtil;
import in.iqing.app.R;
import in.iqing.view.fragment.SettingFragment;

/**
 * Created by neavo on 2014/6/28.
 */

public class SettingActivity extends BaseActivity {

	private boolean fromContent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_setting);
	}

	@Override
	protected void onInitialize(Bundle savedInstanceState) {
		super.onInitialize(savedInstanceState);

		initVariables();
		initActionBar();
	}

	@Override
	public void onBackPressed() {
		if (!fromContent) {
			super.onBackPressed();
		} else {
			Bundle extras = getIntent().getExtras();
			extras.putBoolean("fromcontent", false);

			finish();
			IntentUtil.startActivity(getActivity(), MainActivity.class, extras);
		}
	}

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);

		loadSettingFragment();
	}

	private void initVariables() {
		if (getIntent().getExtras() != null) {
			this.fromContent = getIntent().getExtras().getBoolean("fromcontent");
		}
	}

	private void initActionBar() {
		if (getActionBar() != null) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
			getActionBar().setDisplayShowHomeEnabled(false);
		}
	}

	private void loadSettingFragment() {
		getFragmentManager()
				.beginTransaction()
				.replace(R.id.holder, SettingFragment.newInstance())
				.commit();
	}
}
